// ----------------------------------------------------------------------------
/**
	File: intersectingdates.cpp
	Author: Zef RosnBrick
	Archive: Live Archive
	Problem Number: 2997
*/
// ----------------------------------------------------------------------------

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define leap_year(y) ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0))
#define days(m) ((m) >= 2 ? DAYS[(m) - 1] - DAYS[(m) - 2] : DAYS[0])
#define stillneed(i) (need[i] && !have[i])
#define year(i) ((i) / 10000)
#define month(i) (((i) % 10000) / 100)
#define day(i) ((i) % 100)
#define mdy(i) month(date[i]), day(date[i]), year(date[i])

const int MAX = 146464, DAYS[12] = { 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
bool have[MAX], need[MAX];
int date[MAX];

int parsedate(int y, int m, int d)
{
	if (y == -1)
		scanf("%4d%2d%2d", &y, &m, &d);
	return
		(365 * (y - 1700) + (y - 1701) / 4 - (y - 1701) / 100 + (y - 1601) / 400) // number days in year [1700, y)
	  + (m - 2 >= 0 ? DAYS[m - 2] : 0) // number of days in month [1, m)
		+ (d - 1) //number of days in day [1, d)
		+ (m > 2 && leap_year(y)); // include leap day
}

int main()
{
	int caseno = 0, nx, nr, l, r, count;

	for (int y = 1700; y <= 2100; y++)
		for (int m = 1; m <= 12; m++)
			for (int d = 1; d <= days(m) + (m == 2 && leap_year(y)); d++)
				date[parsedate(y, m, d) + 1] = 10000 * y + 100 * m + d;

	while (++caseno)
	{
		if (!(cin >> nx >> nr) || (nx == 0 && nr == 0))
			return 0;
		else if (caseno > 1)
			printf("\n");

		fill(have, have + MAX, 0);
		for (int i = 0; i < nx; i++)
		{
			l = parsedate(-1, 0, 0);
			r = parsedate(-1, 0, 0);
			fill(have + l + 1, have + r + 2, 1);
		}

		fill(need, need + MAX, 0);
		for (int i = 0; i < nr; i++)
		{
			l = parsedate(-1, 0, 0);
			r = parsedate(-1, 0, 0);
			fill(need + l + 1, need + r + 2, 1);
		}

		count = 0;
		printf("Case %i:\n", caseno);
		for (int i = 1; i < MAX; i++)
			if (stillneed(i) && !stillneed(i - 1))
				printf("    %i/%i/%i", mdy(l = i));
			else if (stillneed(i - 1) && !stillneed(i) && ++count)
				if (i - 1 > l)
					printf(" to %i/%i/%i\n", mdy(i - 1));
				else
					printf("\n");

		if (count == 0)
			printf("    No additional quotes are required.\n");
	}
}
